package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.BuyerBindCsRelationBean;
import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.service.BuyerBindCsRelationCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.sqlwapper.godmember.GodMemberWapper;
import com.ymttest.utils.TestDataManager;
/**
*买家绑定客服
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BuyerBindCsRelation{
	private static BuyerBindCsRelationBean buyerbindcsrelationBean;
	private static BuyerBindCsRelationCall buyerbindcsrelationCall;
	private static Integer shopid ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("买家绑定客服");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		buyerbindcsrelationBean=new BuyerBindCsRelationBean();
		buyerbindcsrelationCall=new BuyerBindCsRelationCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(buyerbindcsrelationCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BuyerBindCsRelation_001() {
		Logger.start(true,"买家绑定客服成功");
		try {
			//开启邀请制
			GodMemberService.setCollectionMobile(shopid, true);
			GodMemberService.setInvitationCodeCall(shopid, true, 0);
			//创建2个客服
			UserCreateBean u = DGUserCallService.initCsUsercreateBean();
			Integer csId = DGUserCallService.UserCreateCall(u);
			UserCreateBean u2 = DGUserCallService.initCsUsercreateBean();
			Integer csId2 = DGUserCallService.UserCreateCall(u2);
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile, csId);
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Logger.verifyEquals(csId, GodMemberWapper.selectMemberByMemberid(memid).get(0).getCsId(), "验证csId");

			buyerbindcsrelationBean.setCsId(csId2);
			buyerbindcsrelationBean.setShopId(shopid);
			buyerbindcsrelationBean.setUserId(userId);
			buyerbindcsrelationCall.setData(buyerbindcsrelationBean);
			buyerbindcsrelationCall.callService();			
			Logger.verifyEquals("200", buyerbindcsrelationCall.getString("code"), "验证code");
			Logger.verifyEquals(csId2, GodMemberWapper.selectMemberByMemberid(memid).get(0).getCsId(), "验证csId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BuyerBindCsRelation_002() {
		Logger.start(true,"shopid不输入失败");
		try {
			buyerbindcsrelationBean.setCsId(1);
//			buyerbindcsrelationBean.setShopId(shopid);
			buyerbindcsrelationBean.setUserId(1);
			buyerbindcsrelationCall.setData(buyerbindcsrelationBean);
			buyerbindcsrelationCall.callService();			
			Logger.verifyEquals("400", buyerbindcsrelationCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BuyerBindCsRelation_003() {
		Logger.start(true,"userid不输入失败");
		try {
			buyerbindcsrelationBean.setCsId(1);
			buyerbindcsrelationBean.setShopId(shopid);
//			buyerbindcsrelationBean.setUserId(1);
			buyerbindcsrelationCall.setData(buyerbindcsrelationBean);
			buyerbindcsrelationCall.callService();			
			Logger.verifyEquals("400", buyerbindcsrelationCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BuyerBindCsRelation_004() {
		Logger.start(true,"csid不输入失败");
		try {
//			buyerbindcsrelationBean.setCsId(1);
			buyerbindcsrelationBean.setShopId(shopid);
			buyerbindcsrelationBean.setUserId(1);
			buyerbindcsrelationCall.setData(buyerbindcsrelationBean);
			buyerbindcsrelationCall.callService();			
			Logger.verifyEquals("400", buyerbindcsrelationCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BuyerBindCsRelation_005() {
		Logger.start(true,"bindtype0绑定客服成功");
		try {
			//未开启邀请制
			GodMemberService.setCollectionMobile(shopid, true);
			GodMemberService.setInvitationCodeCall(shopid, false, 0);
			GodMemberService.setBindTypeBean(shopid, 0);
			//创建2个客服
			UserCreateBean u = DGUserCallService.initCsUsercreateBean();
			Integer csId = DGUserCallService.UserCreateCall(u);
			UserCreateBean u2 = DGUserCallService.initCsUsercreateBean();
			Integer csId2 = DGUserCallService.UserCreateCall(u2);
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile, csId);
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Logger.verifyEquals(csId, GodMemberWapper.selectMemberByMemberid(memid).get(0).getCsId(), "验证csId");

			buyerbindcsrelationBean.setCsId(csId2);
			buyerbindcsrelationBean.setShopId(shopid);
			buyerbindcsrelationBean.setUserId(userId);
			buyerbindcsrelationCall.setData(buyerbindcsrelationBean);
			buyerbindcsrelationCall.callService();			
			Logger.verifyEquals("200", buyerbindcsrelationCall.getString("code"), "验证code");
//			Logger.verifyEquals("false", buyerbindcsrelationCall.getString("data"), "验证data");
			//这里绑定成功了
			Logger.verifyEquals(csId2, GodMemberWapper.selectMemberByMemberid(memid).get(0).getCsId(), "验证csId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BuyerBindCsRelation_006() {
		Logger.start(true,"永久绑定邀请制,不更换客服");
		try {
			//开启邀请制
			GodMemberService.setCollectionMobile(shopid, true);
			GodMemberService.setInvitationCodeCall(shopid, true, 1);
			GodMemberService.setBindTypeBean(shopid, 1);
			//创建2个客服
			UserCreateBean u = DGUserCallService.initCsUsercreateBean();
			Integer csId = DGUserCallService.UserCreateCall(u);
			UserCreateBean u2 = DGUserCallService.initCsUsercreateBean();
			Integer csId2 = DGUserCallService.UserCreateCall(u2);
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile, csId);
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Logger.verifyEquals(csId, GodMemberWapper.selectMemberByMemberid(memid).get(0).getCsId(), "验证csId");

			buyerbindcsrelationBean.setCsId(csId2);
			buyerbindcsrelationBean.setShopId(shopid);
			buyerbindcsrelationBean.setUserId(userId);
			buyerbindcsrelationCall.setData(buyerbindcsrelationBean);
			buyerbindcsrelationCall.callService();			
			Logger.verifyEquals("200", buyerbindcsrelationCall.getString("code"), "验证code");
			Logger.verifyEquals(csId, GodMemberWapper.selectMemberByMemberid(memid).get(0).getCsId(), "验证csId");

//			Logger.verifyEquals("false", buyerbindcsrelationCall.getString("data"), "验证data");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BuyerBindCsRelation_007() {
		Logger.start(true,"买家绑定客服成功-不同商家不受影响");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			//开启邀请制
            GodMemberService.setCollectionMobile(shopid, true);
            GodMemberService.setInvitationCodeCall(shopid, true, 0);
            
            Integer shopid2 = GodmchManageCallService.CreateSellerMch();
			//开启邀请制
            GodMemberService.setCollectionMobile(shopid2, true);
            GodMemberService.setInvitationCodeCall(shopid2, true, 0);
            
			UserCreateBean u = DGUserCallService.initCsUsercreateBean();
			Integer csId = DGUserCallService.UserCreateCall(u);
			UserCreateBean u2 = DGUserCallService.initCsUsercreateBean();
			Integer csId2 = DGUserCallService.UserCreateCall(u2);
			UserCreateBean u3= DGUserCallService.initCsUsercreateBean();
			Integer csId3 = DGUserCallService.UserCreateCall(u3);
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile, csId);
			
			UserCreateBean usercreateBean2 = DGUserCallService.initUsercreateBean();
			int userId2 = DGUserCallService.UserCreateCall(usercreateBean2);
			CreateMemberBean createMem2 = GodMemberService.initCreateMemberBean(shopid2,userId2,usercreateBean2.getOpenId());
			createMem.setOpenId(createMem2.getOpenId());
			String memid2 = GodMemberService.creatememberCall(createMem2);
			GodMemberService.bindMobile(shopid2, userId2, mobile, csId2);
			
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Logger.verifyEquals(csId, GodMemberWapper.selectMemberByMemberid(memid).get(0).getCsId(), "验证csId");
			Logger.verifyEquals(csId2, GodMemberWapper.selectMemberByMemberid(memid2).get(0).getCsId(), "验证csId");
			
			buyerbindcsrelationBean.setCsId(csId3);
			buyerbindcsrelationBean.setShopId(shopid);
			buyerbindcsrelationBean.setUserId(userId);
			buyerbindcsrelationCall.setData(buyerbindcsrelationBean);
			buyerbindcsrelationCall.callService();			
			Logger.verifyEquals("200", buyerbindcsrelationCall.getString("code"), "验证code");
			Logger.verifyEquals(csId3, GodMemberWapper.selectMemberByMemberid(memid).get(0).getCsId(), "验证csId");
			Logger.verifyEquals(csId2, GodMemberWapper.selectMemberByMemberid(memid2).get(0).getCsId(), "验证csId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BuyerBindCsRelation_008() {
		Logger.start(true,"买家绑定客服成功-同商家一起更新");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			//开启邀请制
            GodMemberService.setCollectionMobile(shopid, true);
            GodMemberService.setInvitationCodeCall(shopid, true, 0);
            
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			UserCreateBean usercreateBean2= DGUserCallService.initUsercreateBean();
			int userId2=DGUserCallService.UserCreateCall(usercreateBean2);
			String mobile=TestDataManager.getPhoneNum();
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			//60.小程序 61.h5
			createMem.setAccessSource(0);
			String memid=GodMemberService.creatememberCall(createMem);
			
			CreateMemberBean createMem2 = GodMemberService.initCreateMemberBean(shopid,userId2,usercreateBean2.getOpenId());
			//60.小程序 61.h5
			createMem2.setAccessSource(1);
			String memid2=GodMemberService.creatememberCall(createMem2);
			
			UserCreateBean u = DGUserCallService.initCsUsercreateBean();
			Integer csId = DGUserCallService.UserCreateCall(u);
			UserCreateBean u2 = DGUserCallService.initCsUsercreateBean();
			Integer csId2 = DGUserCallService.UserCreateCall(u2);
			
			GodMemberService.bindMobile(shopid, userId, mobile,csId);
			GodMemberService.bindMobile(shopid, userId2, mobile,csId);
			
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Logger.verifyEquals(csId, GodMemberWapper.selectMemberByMemberid(memid).get(0).getCsId(), "验证csId");
			Logger.verifyEquals(csId, GodMemberWapper.selectMemberByMemberid(memid2).get(0).getCsId(), "验证csId");
			
			buyerbindcsrelationBean.setCsId(csId2);
			buyerbindcsrelationBean.setShopId(shopid);
			buyerbindcsrelationBean.setUserId(userId);
			buyerbindcsrelationCall.setData(buyerbindcsrelationBean);
			buyerbindcsrelationCall.callService();			
			Logger.verifyEquals("200", buyerbindcsrelationCall.getString("code"), "验证code");
			Logger.verifyEquals(csId2, GodMemberWapper.selectMemberByMemberid(memid).get(0).getCsId(), "验证csId");
			Logger.verifyEquals(csId2, GodMemberWapper.selectMemberByMemberid(memid2).get(0).getCsId(), "验证csId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BuyerBindCsRelation_009() {
		Logger.start(true,"买家绑定客服成功-新用户-没有手机号也给更新");
		try {
			//开启邀请制
			GodMemberService.setCollectionMobile(shopid, true);
			GodMemberService.setInvitationCodeCall(shopid, true, 0);
			//创建2个客服
			UserCreateBean u = DGUserCallService.initCsUsercreateBean();
			Integer csId = DGUserCallService.UserCreateCall(u);
			UserCreateBean u2 = DGUserCallService.initCsUsercreateBean();
			Integer csId2 = DGUserCallService.UserCreateCall(u2);
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
//			String mobile=TestDataManager.getPhoneNum();
//			GodMemberService.bindMobile(shopid, userId, mobile, csId);
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
//			Logger.verifyEquals(csId, GodMemberWapper.selectMemberByMemberid(memid).get(0).getCsId(), "验证csId");

			buyerbindcsrelationBean.setCsId(csId2);
			buyerbindcsrelationBean.setShopId(shopid);
			buyerbindcsrelationBean.setUserId(userId);
			buyerbindcsrelationCall.setData(buyerbindcsrelationBean);
			buyerbindcsrelationCall.callService();			
			Logger.verifyEquals("200", buyerbindcsrelationCall.getString("code"), "验证code");
			Logger.verifyEquals(csId2, GodMemberWapper.selectMemberByMemberid(memid).get(0).getCsId(), "验证csId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}